<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>事件代理</title>
</head>
<body>
<div>
    <div id="div1" style="width:500px;height:500px;background-color:black">
    <div id="div2" style="width:300px;height:300px;background-color:green"></div>
    </div>
</div>
<script type="text/javascript">
    document.getElementById("div1").addEventListener("click",function(e) {
        //console.log(e);
        console.log(this);  //this始终是绑定事件的那个标签
        //e.target是触发事件的标签，可能是绑定事件的那个标签，也可能是它的子标签
        e.target.style.backgroundColor = "#0ff";
    });
</script>
</body>
</html>